<?php defined('IN_ADMIN') or exit('No permission resources.');?>
<?php include $this->admin_tpl('header', 'admin');?>
<link rel="stylesheet" href="<?=LAY_PATH?>css/layui.css">

<div class="pad-lr-10" style="width: 850px;margin:auto">
    <form class="layui-form" id="form" method="post" enctype="multipart/form-data" onsubmit="return postdata()" action="">
        <table class="layui-table">
            <thead>
            <tr>
                <td style="width: 80px;text-align: center">ID</td>
                <td style="text-align: center">名称(name)</td>
                <td style="text-align: center">号码(number)</td>
                <td style="text-align: center">备注(beizhu)</td>
                <td style="text-align: center">操作</td>
            </tr>

            </thead>
            <tbody>
            <?php foreach($data as $k=>$v){?>
                <tr id="<?=$v['id']?>">
                    <td style="text-align: center"><?=$v['id']?></td>
                    <td style="width: 100px;text-align: center"><?=$v['name']?></td>
                    <td style="width: 200px;text-align: center"><?=$v['number']?></td>
                    <td style="width: 200px;text-align: center"><?=$v['beizhu']?></td>
                    <td style="text-align: center"><button type="button" class="layui-btn layui-btn-sm edit" onclick="edit(<?=$v['id']?>)" style="background: #2f4050;color:#fff">修改</button> | <button type="button" style="background: #2f4050;color:#fff" class="layui-btn layui-btn-sm" onclick="del(<?=$v['id']?>)">删除</button></td>
                </tr>
            <?php }?>
            </tbody>


        </table>
    </form>
    <div style="width: 120px;margin:auto">
        <button style="background: #2f4050;color:#fff" class="layui-btn add">添加</button>
    </div>



</div>
<script src="<?=LAY_PATH?>layui.js"></script>
<script>

    layui.use(['layer','form'],function(){
        $(".add").click(function(){
            $(".add").css("display","none")
            if($("td").hasClass("edit_c")){
                layer.msg("请先完成图片上传操作或者取消",{icon:2})
            }else {
                $.ajax({
                    url: "index.php?m=webman&c=index&a=tel_add&pc_hash=<?=$_SESSION['pc_hash']?>",
                    type: "post",
                    success: function (msg) {
                        $('tbody').append(msg)
                    }
                })

            }
        })
    })

</script>

<script type="text/javascript">

    /*phpcms函数，窗口撑开*/
    function test_spider(id) {
        window.top.art.dialog({id:'test'}).close();
        window.top.art.dialog({title:'<?php echo L('data_acquisition_testdat')?>',id:'test',iframe:'?m=collection&c=node&a=public_test&nodeid='+id,width:'700',height:'500'}, '', function(){window.top.art.dialog({id:'test'}).close()});
    }

    function copy_spider(id) {
        window.top.art.dialog({id:'test'}).close();
        window.top.art.dialog({title:'<?php echo L('copy_node')?>',id:'test',iframe:'?m=collection&c=node&a=copy&nodeid='+id,width:'420',height:'120'}, function(){var d = window.top.art.dialog({id:'test'}).data.iframe;var form = d.document.getElementById('dosubmit');form.click();return false;}, function(){window.top.art.dialog({id:'test'}).close()});
    }

    function import_spider() {
        window.top.art.dialog({id:'test'}).close();
        window.top.art.dialog({title:'<?php echo L('import_collection_points')?>',id:'test',iframe:'?m=collection&c=node&a=node_import',width:'420',height:'200'}, function(){var d = window.top.art.dialog({id:'test'}).data.iframe;var form = d.document.getElementById('dosubmit');form.click();return false;}, function(){window.top.art.dialog({id:'test'}).close()});
    }
    /*phpcms函数，窗口撑开*/

    /*临时图片显示函数*/
    function preview(file)
    {
        var prevDiv = document.getElementById('preview');
        if (file.files && file.files[0])
        {
            var reader = new FileReader();
            reader.onload = function(evt){
                prevDiv.innerHTML = '<img src="' + evt.target.result + '" height="80" width="300"  />';
            };
            reader.readAsDataURL(file.files[0]);
        }
        else
        {
            prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
        }
    }

    window.top.$('#display_center_id').css('display','none');
    //-->
    /*ajax删除*/
    function del(id){
        layer.confirm('确定删除吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function(index, layero){
            $.post("index.php?m=webman&c=index&a=tel_delete&pc_hash=<?=$_SESSION['pc_hash']?>", {id: id}, function (msg) {
                if (msg == "ok") {
                    layer.msg('删除成功', {icon: 1}, function () {
                        location.reload();
                    })
                }
            })
        }, function(index){
            
        });
    }


    function edit(id){
        $(".add").css("display","none")
        $.post("index.php?m=webman&c=index&a=tel_edit&pc_hash=<?=$_SESSION['pc_hash']?>",{id:id},function (msg) {
            $("#"+id).html(msg)
        });
    }

    function add1(){
        $.ajax({
            url:"index.php?m=webman&c=index&a=tel_add&pc_hash=<?=$_SESSION['pc_hash']?>",
            type:"post",
            data:$("#form").serialize(),
            success:function(msg){
               if(msg=='ok'){
                   layer.msg('添加成功',{icon:1}, function () {
                       location.reload();
                   })
               }else if(msg=='fail'){
                   layer.msg('添加失败，请联系管理员',{icon:2})
               }else{
                   layer.msg(msg,{icon:2})
               }
            }
        })
    }
    function edit1(){
        $.ajax({
            url:"index.php?m=webman&c=index&a=tel_edit&pc_hash=<?=$_SESSION['pc_hash']?>",
            type:"post",
            data:$("#form").serialize(),
            success:function(msg){
                if(msg=='ok'){
                    layer.msg('修改成功',{icon:1},function(){
                        location.reload();
                    })
                }else if(msg=='fail'){
                    layer.msg('添加失败，请联系管理员',{icon:2})
                }else{
                    layer.msg(msg,{icon:2})
                }
            }
        })
    }
</script>
<script>



    layui.use(['layer','form','upload','jquery'], function(){
        var form = layui.form;  var layer = layui.layer;
        var $ = layui.jquery
            ,upload = layui.upload;




    });

</script>
</body>
</html>